<template>
  <el-drawer
    :wrapperClosable="false"
    direction="rtl"
    custom-class="demo-drawer"
    :title="title"
    ref="drawer"
    size="40%"
    :visible.sync="dialogFormVisible"
  >
    <div class="demo-drawer__content">
      <el-form ref="form" label-width="auto" :model="form" :rules="rules">
        <el-form-item label="变更积分:" prop="changeScore">
          <el-input-number
            :max="form.changeType === 4 ? 3 : form.changeType === 7 ? 8 : 0"
            v-model="form.changeScore"
            @change="handleChange"
            label="描述文字"
          ></el-input-number>
        </el-form-item>

        <el-form-item label="积分变动说明:" prop="memo">
          <el-input v-model="form.memo" type="textarea" :rows="10" placeholder="请输入本次积分变动说明"></el-input>
        </el-form-item>
      </el-form>
      <div class="demo-drawer__footer">
        <el-button @click="close" type="warning">取 消</el-button>
        <el-button type="primary" @click="save">确 定</el-button>
      </div>
    </div>
  </el-drawer>
</template>

<script>
  import { SetUserWeekScore } from '@/api/userManagement'

  export default {
    name: 'UserManagementEdit',
    data() {
      return {
        form: {
          changeScore: 0,
          changeType: 1,
          changeUserId: 0,
          changeMemo: '后台管理员修改积分',
          memo: '',
        },
        rules: {
          changeScore: [{ required: true, trigger: 'blur', message: '请输入变更积分' }],
          memo: [{ required: true, trigger: 'blur', message: '请输入本次积分变动说明' }],
        },
        title: '变更积分',
        dialogFormVisible: false,
      }
    },
    created() {},
    methods: {
      handleChange() {},
      showEdit(row) {
        this.form = Object.assign({}, row)
        this.dialogFormVisible = true
      },
      close() {
        this.$refs['form'].resetFields()
        this.form = this.$options.data().form
        this.dialogFormVisible = false
      },
      save() {
        this.$refs['form'].validate(async (valid) => {
          if (valid) {
            const { msg } = await SetUserWeekScore(this.form)
            this.$baseMessage(msg, 'success')
            this.$emit('fetch-data')
            this.close()
          } else {
            return false
          }
        })
      },
    },
  }
</script>

<style lang="scss" scoped>
  ::v-deep .demo-drawer__content {
    height: 100%;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    flex-direction: column;
    .demo-drawer__footer {
      bottom: 0;
    }
  }
</style>
